package com.kstech.mp3604

import com.kstech.mp3604.base.Global
import com.kstech.mp3604.utils.DataUtil
import com.kstech.mp3604.utils.DataUtil.intToHex4
import com.kstech.mp3604.utils.TimeUtil
import com.kstech.mp3604.utils.TimeUtil.convertTime
import org.junit.Test

class Test1 {
    @Test
    fun main9() {
//        println(SPUtils.getInstance().getFloat("blankii"))
        println("1234".toByteArray())
//        var a: Int = 0
//        a = -33
//        println(DataUtil.intToHex2(99))
//        println(DataUtil.sIntToHex(-99))
//        println(40 / 100.0)
    }

    @Test
    fun main8() {
        println(34f / 10)
        println(TimeUtil.isoToMillisLegacy("2025-07-23T20:08:38.718425400"))
        println(DataUtil.hexB2L("2014"))
        println(Global.typeNameArr.indexOf("122"))
        println(Global.typeNameArr.indexOf("333"))
    }

    @Test
    fun main7() {

        println(10 * 2000.0)

        println(convertTime(1714357362573))
        println(intToHex4(-1))


        println(
            DataUtil.intToHex4(
                "4.2".toDouble().toInt()
            )
        )
    }

    @Test
    fun main6() {
        // 1. 小端序 → 数值（"FEFF" → 0xFFFE）
        val value = "0100".chunked(2).reversed().joinToString("").toUShort(16)

        // 2. 转为16位二进制字符串（补零到16位）
        val binaryStr = value.toString(2).padStart(16, '0')

        binaryStr.reversed().forEach {
            println(it)
        }

//         提取 8 位二进制数组（低位在前）
//        val arr0 = IntArray(8) { index ->
//            ("12".toInt(16) shr index) and 0x01
//        }
//
//        arr0.forEach {
//            println(it)
//        }

    }

    @Test
    fun main5() {
        println(DataUtil.hexToSLong("FFFFFFFF"))//-1
        println(DataUtil.hexToSLong("32425313"))//324223538
        println(DataUtil.hexToSLong("53521FF1"))//-249605549

        println(DataUtil.hexToSInt("1234"))//13330
        println(DataUtil.hexToUInt("1234"))//13330


        println(DataUtil.hexToSInt("FFFF"))//-1
        println(DataUtil.hexToUInt("FFFF"))//65535
    }

    @Test
    fun main4() {
        val string_arr = arrayOf("123", "32", "44", "53")

        string_arr.forEach {
            println("forEach ")
        }
        string_arr.forEachIndexed { index, value ->
            println("====>$index  -=======>${value}")
        }

        println("main4 end")
    }

    @Test
    fun main3() {
        println(-1234.toDouble() / 1000)
        println("%.1f".format((10001 - 444).toDouble() / 1000))//9.6
    }

    @Test
    fun main2() {
        println(TimeUtil.getTimeStamp())
        println(TimeUtil.getTimeStamp_second())
    }

    @Test
    fun main() {
        /**
         * 使用枚举
         */
        println(Global.RunningStatus.DM_FINISHED.name)//DM_FINISHED
        println(Global.RunningStatus.DM_FINISHED.ordinal)//4
        println(Global.RunningStatus.DM_FINISHED.data)//5
    }

//    @Test
//    fun main1() {
//        /**
//         * 使用枚举
//         */
//        println("值：${20 % 10}")//DM_FINISHED
//        SerialManager.setRev0210Listener(this)
//        SerialManager.setRev0310Listener(this)
//        SerialManager.setRev0410Listener(this)
//        SerialManager.upPackHexString("0210456789ABCDEF01230310456789ABCDEF01000410456789ABCDEF0023")
//    }
//
//    override fun data_0210(data1: Long, data2: Long, data3: Long, data4: Long) {
//        println("0210:data1:$data1,data2:$data2,data3:$data3,data4:$data4")
//    }
//
//    override fun data_0310(data1: Long, data2: Long, data3: Long) {
//        println("0310:data1:$data1,data2:$data2,data3:$data3")
//    }
//
//    override fun data1_0410(data1: Int, data2: Int) {
//        println("data1_0410:data1:$data1,data2:$data2")
//    }
//
//    override fun data2_0410(data1: Int, data2: Int, data3: Int, data4: Int, data5: Int) {
//        println("data2_0410:data1:$data1,data2:$data2,data3:$data3,data4:$data4,data5:$data5")
//    }
//
//    override fun data3_0410(
//        data1: Int, data2: Int, data3: Int, data4: Int, data5: Int, data6: Int
//    ) {
//        println("data3_0410:data1:$data1,data2:$data2,data3:$data3,data4:$data4,data5:$data5,data6:$data6")
//    }
//
//    override fun data4_0410(data1: Long) {
//        println("data4_0410:data1:$data1")
//    }


}